<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录页面</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">
</head>
<body>
    <div class="nav">
        五子棋对战
    </div>
    <div class="login-container">
        <!-- 登录界面对话框 -->
        <div class="login-dialog">
            <h3>登录</h3>
            <!-- 登录这一行 -->
            <div class="row">
                <span>用户名</span>
                <input type="text" id="username">
            </div>
            <!-- 密码这一行 -->
            <div class="row">
                <span>密码</span>
                <input type="password" id="password">
            </div>
            <!-- 提交按钮 -->
            <div class="row">
                <button id="submit" onclick="mysub()">登录</button>
            </div>
        </div>
    </div>
</body>
<script src="js/jquery.min.js"></script>
<script>
    function mysub(){
        var username = jQuery("#username");
        var password = jQuery("#password");
        if(username.val() == ""){
            alert("请先输入用户名");
            username.focus();
            return;
        }
        if(password.val() == ""){
            alert("请输入密码")
            password.focus();
            return;
        }
        {
            jQuery.ajax({
                url: "/user/login",
                type: "POST",
                data: {"username": username.val(),"password": password.val()},
                success: function(result){
                    if(result != null && result.data != null && result.code == 200){
                        if(confirm("登录成功 页面是否跳转")){
                            // 跳转到游戏大厅页面
                            location.href = "/gamehall.html";
                        }
                    }else{
                        alert(result.msg);
                    }
                }
            });
        }
    }
</script>
</html>